package POJO;

import java.math.BigDecimal;

public class Express {
	private int id;
	private int companyId;
	private String name;
	private BigDecimal balance;
	private int status;
	private BigDecimal overdueBalance;
	private int payWay;
	private BigDecimal cost;
	private String hotLine;

	public int getId() {
		return id;
	}

	public int getCompanyId() {
		return companyId;
	}

	public String getName() {
		return name;
	}

	public double getBalance() {
		return balance.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	public int getStatus() {
		return status;
	}

	public double getOverdueBalance() {
		return overdueBalance.setScale(2, BigDecimal.ROUND_HALF_UP)
				.doubleValue();
	}

	public int getPayWay() {
		return payWay;
	}

	public double getCost() {
		return cost.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setCompanyId(int companyId) {
		this.companyId = companyId;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setBalance(double balance) {
		this.balance = new BigDecimal(balance);
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public void setOverdueBalance(double overdueBalance) {
		this.overdueBalance = new BigDecimal(overdueBalance);
	}

	public void setPayWay(int payWay) {
		this.payWay = payWay;
	}

	public void setCost(double cost) {
		this.cost = new BigDecimal(cost);
	}

	public String getHotLine() {
		return hotLine;
	}

	public void setHotLine(String hotLine) {
		this.hotLine = hotLine;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	public void setOverdueBalance(BigDecimal overdueBalance) {
		this.overdueBalance = overdueBalance;
	}

	public void setCost(BigDecimal cost) {
		this.cost = cost;
	}

	public int getPayAlarm() {

		if (payWay == 0 || payWay == 1) {
			// pre-paid
			if (balance.subtract(cost.abs()).compareTo(new BigDecimal(0.0)) == -1) {
				// balance<0
				if (payWay == 0
						&& balance.subtract(cost.abs()).abs()
								.compareTo(overdueBalance.abs()) == 1) {
					return 2;
				}
				return 1;
			}
		}
		return 0;
	}

	/**
	 * 处理扣费
	 * 
	 * @return
	 */
	public boolean deal() {
		if (getPayAlarm() == 2) {
			return false;
		} else {
			balance = balance.subtract(cost.abs());
			return true;
		}
	}

	public String toString() {
		return String
				.format("id=%s , name=%s ,balance=%s , staus=%s ,overdueBalance=%s,payWay=%s cost=%s ",
						id, name, getBalance(), status, getOverdueBalance(),
						getPayWay(), getCost());
	}
}
